package com.example.demo.ws.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.example.demo.entity.Student;
import com.example.demo.mapper.StudentMapper;
import com.example.demo.pojo.dto.add.StudentAddDto;
import com.example.demo.ws.TestWebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.jws.WebService;

/**
 * webservice服务接口测试.参考自：https://www.jianshu.com/p/354522360e21
 *
 * @author TongDaShuai
 * @since 2021/10/27
 */
@WebService(serviceName = "testWebService", // 与接口中指定的name一致
        targetNamespace = "http://webservice.tds.com/", // 与接口中的命名空间一致,一般是接口的包名倒
        endpointInterface = "com.example.demo.ws.TestWebService"// 接口地址
)
@Component
public class TestWebServiceImpl implements TestWebService {

    @Resource
    private StudentMapper studentMapper;

    /**
     * 暴露的服务方法sayHello
     * @param name
     * @return
     */
    @Override
    public String sayHello(String name) {
        return "你好！";
    }

    /**
     * 暴露的服务方法saveUser
     * @param student
     * @return
     */
    @Override
    public String saveUser(StudentAddDto student) {
        Student addDo = new Student();
        BeanUtil.copyProperties(student, addDo);
        studentMapper.insert(addDo);
        return JSONUtil.toJsonStr(addDo);
    }
}
